import requests

from common.get_token import get_login_token


class IhrmEmpApi(object):
    @classmethod
    def add_emp(cls,token,request_data):
        resp = requests.post(url="http://ihrm-test.itheima.net/api/sys/user/",
                             headers={"Authorization": token},
                             json = request_data)
        return resp

    @classmethod
    def modify_emp(cls, id, token,request_data):
        resp = requests.put(url="http://ihrm-test.itheima.net/api/sys/user/" + id,
                                headers={"Authorization": token},
                                json=request_data)
        return resp

    @classmethod
    def query_emp(cls, id, token):
        resp = requests.get(url="http://ihrm-test.itheima.net/api/sys/user/" + id,
                            headers={"Authorization": token})

        return resp

    @classmethod
    def delete_emp(cls, id, token):
        resp = requests.delete(url="http://ihrm-test.itheima.net/api/sys/user/" + id,
                               headers={"Authorization": token})

        return resp


if __name__ == '__main__':
    emp_id ='1525031610699808768'
    token = get_login_token()

    add_data = {"username":"hha","mobile":"13469897399","workNumber":"1324312"}
    resp = IhrmEmpApi.add_emp(get_login_token(),add_data)
    print("添加员工",resp)
    modify_data = {"username": "李主播"}

    resp = IhrmEmpApi.modify_emp(emp_id,token,modify_data)
    print("修改员工", resp)

    resp = IhrmEmpApi.query_emp(emp_id, token)
    print("查询员工", resp)

    resp = IhrmEmpApi.delete_emp(emp_id, token)
    print("删除员工", resp)

